/*
 * disk.c
 *
 *  Created on: Dec 25, 2012
 *      Author: andrey
 *
 *
 * MISO		red			A6
 * SCLK		grey		A5
 * MOSI		white		A7
 * CS		black		B6
 */

#include "rficonsole.h"
#include "diskio.h"

BYTE Buff[4*1024] __attribute__ ((aligned (4))) ;		/* Working buffer */


void invoke_disk_initialize() {
	print("rc=%d\n", disk_initialize(0));
}

void print_disk_info() {
	BYTE res, b1;
	long p1, p2, p3;
	WORD w1;

	Buff[0]=2;
	if (disk_ioctl(0, CTRL_POWER, Buff) == RES_OK )
		{ print("Power is %s\n", Buff[1] ? "ON" : "OFF"); }
	if (disk_ioctl(0, GET_SECTOR_COUNT, &p2) == RES_OK)
		{ print("Drive size: %lu sectors\n", p2); }
	if (disk_ioctl(0, GET_SECTOR_SIZE, &w1) == RES_OK)
		{ print("Sector size: %u\n", w1); }
	if (disk_ioctl(0, GET_BLOCK_SIZE, &p2) == RES_OK)
		{ print("Erase block size: %lu sectors\n", p2); }
	if (disk_ioctl(0, MMC_GET_TYPE, &b1) == RES_OK)
		{ print("MMC/SDC type: %u\n", b1); }
//	if (disk_ioctl(0, MMC_GET_CSD, Buff) == RES_OK)
//		{ xputs("CSD:\n"); put_dump(Buff, 0, 16); }
//	if (disk_ioctl(0, MMC_GET_CID, Buff) == RES_OK)
//		{ xputs("CID:\n"); put_dump(Buff, 0, 16); }
//	if (disk_ioctl(0, MMC_GET_OCR, Buff) == RES_OK)
//		{ xputs("OCR:\n"); put_dump(Buff, 0, 4); }
//	if (disk_ioctl(0, MMC_GET_SDSTAT, Buff) == RES_OK) {
//		xputs("SD Status:\n");
//		for (s1 = 0; s1 < 64; s1 += 16) put_dump(Buff+s1, s1, 16);
//	}

}


void initSd() {
	addConsoleAction("init", &invoke_disk_initialize);

	invoke_disk_initialize();
	print_disk_info();



}


